package dwrealtime;
import java.awt.image.BufferedImage;

import javax.xml.bind.DatatypeConverter;

//import com.qs.QsFaceEngine;
//import com.qs.Util;
//import com.qs.QsFaceEngine.QsFace;
//import com.qs.QsFaceEngine.QsFace.ByReference;
import dwbrowser.QsFaceEngine;
//import dwbrowser.QsFaceEngine.QsFace.ByReference;
import dwbrowser.Util;
import dwbrowser.QsFaceEngine.QsFace;
import dwbrowser.QsFaceEngine.QsFace.ByReference;

public class Test {

    public static void main(String[] args) throws Exception {

        long handler = QsFaceEngine.create();
        float score;
        int facenum;
        System.out.println(handler);
//        score = QsFaceEngine.compare2Image(handler, "1.jpg", "2.jpg");
//        System.out.println("图片比较:" + score);

        BufferedImage img1 = Util.toBufferedImage("D:/code/2018/server/java/dwserver/dw/WebRoot/pics/12.jpg");
        BufferedImage img2 = Util.toBufferedImage("D:/code/2018/server/java/dwserver/dw/WebRoot/pics/11.jpg");

        // 人脸检测
        QsFace[] face1 = new QsFace[10];
        QsFace[] face2 = new QsFace[10];
        facenum = QsFaceEngine.detectFaces(handler, Util.toBytes(img1), img1.getWidth(), img1.getHeight(),
            img1.getWidth() * 3, face1, 10);
        System.out.println("facenum0:" + facenum);
        facenum = QsFaceEngine.detectFacesV2(handler, Util.toBytes(img2), img2.getWidth(), img2.getHeight(),
            img2.getWidth() * 3, face2, 10);
        System.out.println("facenum1:" + facenum);
        facenum = QsFaceEngine.detectFacesReinforce(handler, Util.toBytes(img2), img2.getWidth(),
            img2.getHeight(), img2.getWidth() * 3, face2, 10);
        System.out.println("facenum2:" + facenum);

        ByReference f1 = face1[0].asReference();
        ByReference f2 = face2[0].asReference();

        // 这里比较两张照片，并且都只有一张脸，多个做 for 循环
        QsFaceEngine.extractFeature(handler, Util.toBytes(img1), img1.getWidth(), img1.getHeight(),
            img1.getWidth() * 3, f1);
        QsFaceEngine.extractFeature(handler, Util.toBytes(img2), img2.getWidth(), img2.getHeight(),
            img2.getWidth() * 3, f2);
        score = QsFaceEngine.compare2Feature(handler, f1.feature, f2.feature);
        System.out.println("特征比较:" + score);
        System.out.println("特征 f1.feature: " + f1.feature+"   特征 f2.feature: " + f2.feature );
        String featureHex1 = DatatypeConverter.printHexBinary(f1.feature);
        System.out.printf("featureHex1: 0x%s\n", featureHex1);
        String featureHex2 = DatatypeConverter.printHexBinary(f2.feature);
        System.out.printf("featureHex2: 0x%s\n", featureHex2);
    }
}
